package gui;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JComponent;
import javax.swing.plaf.basic.BasicScrollBarUI;

public class CustomScrollBarUI extends BasicScrollBarUI {


	private Image imageTrack;
	CustomScrollBarUI() {
		try {
			imageTrack = ImageIO.read(new File("images\\menuBackground.png"));
		} catch (IOException e){}
	}
	protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {        
		g.translate(thumbBounds.x, thumbBounds.y);
		g.setColor(new Color(248,218,88));
		g.drawRoundRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1,5,5 );
		((Graphics2D)g).fillRoundRect( 0, 0, thumbBounds.width - 2, thumbBounds.height - 1,5,5 );
		g.translate( -thumbBounds.x, -thumbBounds.y );
	}

	@Override
	protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {        
		g.translate(trackBounds.x, trackBounds.y);

		for (int w = 0 ; w< trackBounds.width; w += imageTrack.getWidth(null) ){
			for (int h =0; h < trackBounds.height; h+= imageTrack.getHeight(null)){
				((Graphics2D)g).drawImage(imageTrack,w,h,null);
			}
		}
		g.translate( -trackBounds.x, -trackBounds.y );
	}
}
